package br.ebula.apl.fabrica;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class FabricaConexoes {

	private String banco = "ebula";
	private String user = "root";
	private String pwd = "";
	
	private String url = "jdbc:mysql://localhost/";
	private String driver = "com.mysql.jdbc.Driver";

	private static FabricaConexoes fabrica;

	private Connection conexao;

	private FabricaConexoes() {
		super();
	}

	private void inicializaConexao() {
		try {
			
			Class.forName(driver);
			conexao = DriverManager.getConnection(url+banco, user, pwd);

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static FabricaConexoes getInstancia() {
		if (fabrica == null) {
			fabrica = new FabricaConexoes();
		}

		return fabrica;
	}

	public Connection getConexao() {
		
		if (conexao == null) {
			inicializaConexao();
		}

		return conexao;
	}

	
}
